import request from '@/api/request'
import type { ApiResponse } from '@/types/http'

export interface LoginParams {
    username: string
    password: string
    code: string
    uuid: string
}

export interface CaptchaResponse {
    captchaId: string
    captchaImage: string
}
export interface UserInfo {
    id: number
    username: string
    // 注意：后端若返回加密密码，不建议在前端使用；此处标为可选
    password?: string
    email: string
    phone: string
    nickname: string
    avatar: string
    status: number // 0: 禁用, 1: 正常
    lastLoginTime: string
    lastLoginIp: string
    createTime: string
    updateTime: string
    isDeleted: number // 0: 未删除, 1: 已删除
}
export interface LoginResponse {
    token: string
    userInfo: UserInfo
}

// 登录API
export function loginApi(params: LoginParams): Promise<ApiResponse<LoginResponse>> {
    return request.post('/auth/login', params)
}

// 获取验证码API
export function getCaptchaApi(): Promise<ApiResponse<CaptchaResponse>> {
    return request.get('/captcha/image')
}
